package com.atom.module.mvvm.base

import android.app.Application
import android.os.Bundle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import com.atom.module.mvvm.livedata.SingleLiveData
import java.util.*

abstract class AbstractViewModel<M : IModel> : ViewModel, IViewModel {

    val model: M

    constructor(model: M) : super() {
        this.model = model
    }

    override fun onCleared() {
        super.onCleared()
        model.onCleared()
    }

    open fun <T : Application> getApplication(): T {
        return AbstractApplication.getInstance() as T
    }

    override fun lifecycleOwner(lifecycleOwner: LifecycleOwner) {
        lifecycleOwner.lifecycle.addObserver(this)
    }
}